import 'package:flutter/material.dart';
import 'package:power_house/util/common_picker.dart';
import 'package:power_house/widgets/common_form_item.dart';

class CommonSelectFormItem extends StatelessWidget {
  final String label;
  final int value;
  final List<String> options;
  final Function(int)? onChange;

  const CommonSelectFormItem({Key? key, required this.label, required this.value, required this.options, required this.onChange}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () {
        var result = CommonPicker.showPicker(context, options, value);

        result.then((selectedValue) {
          if (value == selectedValue) {
            return;
          }
          if (selectedValue == null) {
            return;
          }
          if (onChange == null) {
            return;
          }
          onChange!(selectedValue);
        });
      },
      child: CommonFormItem(
        label: label,
        contentBuilder: (context) => SizedBox(
          height: 40.0,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                options[value],
                style: const TextStyle(fontSize: 16.0),
              ),
              const Icon(Icons.keyboard_arrow_right),
            ],
          ),
        ),
      ),
    );
  }
}
